// 斐波那契数列
// n == 1 || n == 2   return 1
// n == 0 return 0
// n > 2 return item[n - 1] + item[n - 2]

function fibonacci(num: number):number {
    if(num == 0){
        return 0;
    }
    if(num == 1 || num == 2){
        return 1
    }

    return fibonacci(num-1) + fibonacci(num-2)
}


// 强化记忆的 斐波那契数列
function fibonacciMemoization(num:number):number{
    let memo = [0,1,1];
    function fibonacci_block(this: any,  n:number):number{
        if(memo[n]!=undefined){
            return memo[n];
        }
        return memo[n] = fibonacci_block.call(this,n-1) + fibonacci_block.call(this,n-2)
    }
    return fibonacci_block(num);
}
console.log(fibonacciMemoization(6));
